<<<<<<< HEAD
var uuuu = JSON.parse(localStorage.getItem('data2'))
$('.tx1 p').html('')
$('.tx1 p').append(uuuu.user)
=======
// 渲染列表
function xr() {
    $.ajax({
        url: "http://47.94.4.201/index.php/index/teacher/teacherlist",
        type: "get",
        dataType: "json",
        success: function(a) {
            var data = a.data.data
            data.forEach(item => {
                $('tbody').append(`<tr>
                            <td>${item.id}</td>
                            <td>${item.name}</td>
                            <td>${item.nick}</td>
                            <td>${item.birthdata}</td>
                            <td>${item.sex}</td>
                            <td>${item.teachertype}</td>
                            <td><button onclick="view(${item.id})">查看</button><button onclick="xg(${item.id})">编辑</button></td>
                        </tr>`)
            })
        },
        error: function(data) {
            console.log(data);
        }
    })
}
>>>>>>> d7f987ffae4259d01a9a73690d4ed924d9055da2


// 分页
const apiUrl = "http://47.94.4.201/index.php/index/teacher/teacherlist";
let currentPage = 1;
const pageLimit = 7;

// 请求数据
async function fetchData(page) {
    if (page < 1) return;

    const response = await fetch(`${apiUrl}?page=${page}&pagelimit=${pageLimit}`);
    const result = await response.json();

    if (result.code === 0) {
        const dataList = result.data.data;
        const pageCount = result.data.pagecount;

        if (page > pageCount) return;

        currentPage = page;
        renderList(dataList);
        document.getElementById("current-page").innerText = currentPage;
        document.getElementById("total-pages").innerText = Math.ceil(pageCount / 7);
        $('tr:even').css('background-color', 'rgb(255, 255, 255)')
        $('tr:odd').css('background-color', 'rgb(249, 249, 249)')
    }
}

function renderList(data) {
    const dataListDiv = document.getElementById("data-list");
    dataListDiv.innerHTML = data
        .map(item => `<tr>
                            <td>${item.id}</td>
                            <td>${item.name || ''}</td>
                            <td>${item.nick || ''}</td>
                            <td>${item.birthdata || ''}</td>
                            <td>${item.sex === 0 ? '男' : item.sex === 1 ? '女' : ''}</td>
                            <td>${item.iphone || ''}</td>   
                            <td><button onclick="view(${item.id})" class="btn1">查看</button><button onclick="xg(${item.id})" class="btn1">编辑</button><button onclick="zx(${item.id})" class="btn2">注销</button></td>
                        </tr>`)
        .join("");
}

fetchData(1); // 初始化加载第一页

// 查看
function view(id) {
    sessionStorage.setItem('id', id)
    location.assign('./讲师详情.html')
}
// 查看所有
<<<<<<< HEAD
function cksy() {
    $('tbody').html('')
    $('thead').html('')
    $('thead').append(` <tr>
                        <th>编号</th>
                        <th>姓名</th>
                        <th>昵称</th>
                        <th>出生日期</th>
                        <th>性别</th>
                        <th>手机号码</th>
                        <th>操作</th>
                    </tr>`)
    fetchData(1)
}
=======
// function cksy() {
//     $('tbody').html('')
//     $('thead').html('')
//     $('thead').append(` <tr>
//                         <th>编号</th>
//                         <th>姓名</th>
//                         <th>昵称</th>
//                         <th>出生日期</th>
//                         <th>性别</th>
//                         <th>手机号码</th>
//                         <th>操作</th>
//                     </tr>`)
//     fetchData(1)
// }
>>>>>>> ccd5b64437f1fc8839e14dad53dc55171b191804
// 修改
var i

function xg(id) {
    i = id
    $('.gl').css('display', 'none')
    $('.xg').css('display', 'block')
    $('.p1 span').html("")
    $('.p1 span').html("/讲师编辑")
}
// 编辑
function bj() {
    var name1 = $('.xg input').eq(0).val()
    var birthdata1 = $('.xg input').eq(1).val()
    var sex1
    var s = document.querySelectorAll('.inp1')
    s.forEach(item => {
        if (item.checked == true) {
            sex1 = item.value
        };
    })
    console.log(name1, birthdata1, sex1);
    
    $.ajax({
        type: 'post',
        url: 'http://47.94.4.201/index.php/index/index/upteacher',
        data: {
            id: i,
            name: name1,
            birthdata: birthdata1,
            sex: sex1
        },
        dataType: 'json',
        success: (a) => {
            alert(a.msg)
            console.log(a);
            $('.gl').css('display', 'block')
            $('.xg').css('display', 'none')
            fetchData(1)
        },
        error: (e) => {
            console.log(e);
        }
    })
}
<<<<<<< HEAD
// 个人中心
var a = sessionStorage.getItem('data')
var data = JSON.parse(a).data
data.forEach(item => {
    $('.tx1 p').append(item.user)
})
var userid
data.forEach(item => {
    userid = item.user
})

function grzx() {
    $('.gl').css('display', 'none')
    $('.grzx').css('display', 'block')
}
$.ajax({
        url: 'http://47.94.4.201/index.php/index/index/getmycenter',
        type: 'get',
        data: {
            userid: userid
        },
        dataType: 'json',
        success: (a) => {
            console.log(a);
        },
        error: (e) => {
            console.log(e);
        }
    })
    // 添加
=======
// 取消编辑
function qxbj() {
    $('.gl').css('display', 'block')
    // $('.b').css('display', 'none')
    $('.xg').css('display', 'none')
    $('.p1 span').html("")
    $('.p1 span').html("/讲师列表")
    fetchData(1)
}
// 个人基本信息
function xrgr() {
    var data3 = JSON.parse(localStorage.getItem('data2'))
    $('.xx').html('')
        $('.xx').append(`<ul>
                                <li><div>姓名</div>${data3.name}</li>
                                <li><div>头像</div><img src=${data3.img} alt=""></li>
                                <li><div>昵称</div>${data3.user}</li>
                                <li><div>性别</div>${data3.sex}</li>
                                <li><div>出生日期</div>${data3.csrq}</li>
                                <li><div>籍贯</div>${data3.jg}</li>
                                <li><div>手机号码</div>${data3.sjhm}</li>
                                <li><div>电子邮箱</div>${data3.dzyx}</li>
                                <li><div>入职日期</div>${data3.rzrq}</li>
                                <li><div>个人介绍</div>${data3.grjs}</li>
                            </ul>`)
}
// 点击修改个人信息
function bjxx() {
    $('.xx').css('display', 'none')
    $('.cc').css('display', 'block')
}
// 修改个人信息
function tjxx() {
    localStorage.clear()
    var name = $('.cc input').eq(0).val()
    var img = $('.cc input').eq(1).val()
    var user = $('.cc input').eq(2).val()
    var sex = $('.cc input').eq(3).val()
    var csrq = $('.cc input').eq(4).val()
    var jg = $('.cc input').eq(5).val()
    var sjhm = $('.cc input').eq(6).val()
    var dzyx = $('.cc input').eq(7).val()
    var rzrq = $('.cc input').eq(8).val()
    var grjs = $('.cc input').eq(9).val()
    var arr = {
        name,
        img,
        user,
        sex,
        csrq,
        jg,
        sjhm,
        dzyx,
        rzrq,
        grjs
    }
    $('.xx').html('')
    $('.xx').append(`<ul>
                            <li><div>姓名</div>${arr.name}</li>
                            <li><div>头像</div><img src=${arr.img} alt=""></li>
                            <li><div>昵称</div>${arr.user}</li>
                            <li><div>性别</div>${arr.sex}</li>
                            <li><div>出生日期</div>${arr.csrq}</li>
                            <li><div>籍贯</div>${arr.jg}</li>
                            <li><div>手机号码</div>${arr.sjhm}</li>
                            <li><div>电子邮箱</div>${arr.dzyx}</li>
                            <li><div>入职日期</div>${arr.rzrq}</li>
                            <li><div>个人介绍</div>${arr.grjs}</li>
                        </ul>`)
    localStorage.setItem('data2', JSON.stringify(arr))
    $('.tx1 p').html('')
    $('.tx1 p').append(arr.user)
    $('.xx').css('display', 'block')
    $('.cc').css('display', 'none')
}
// 取消修改
function qxxg() {
    $('.xx').css('display', 'block')
    $('.cc').css('display', 'none')
}
// 添加
>>>>>>> ccd5b64437f1fc8839e14dad53dc55171b191804
function add() {
    $('.gl').css('display', 'none')
    $('.tj').css('display', 'block')
    $('.p1 span').html("")
    $('.p1 span').html("/讲师添加")
}

function add1() {
    var name = $('.tj input').eq(0).val()
    var nick = $('.tj input').eq(1).val()
    var birthdata = $('.tj input').eq(2).val()
    var iphone = $('.tj input').eq(3).val()
    var teachertype = $('select').val()
    var sex
    var s1 = document.querySelectorAll('.inp2')
    s1.forEach(item => {
        if (item.checked == true) {
            sex = item.value
        }
    })
    $.ajax({
        url: 'http://47.94.4.201/index.php/index/index/addteacher',
        type: 'post',
        data: {
            name: name,
            nick: nick,
            birthdata: birthdata,
            iphone: iphone,
            teachertype: teachertype,
            sex: sex
        },
        dataType: 'json',
        success: (a) => {
            $('.gl').css('display', 'block')
            $('.tj').css('display', 'none')
            fetchData(1)
        },
        error: (e) => {
            console.log(e);
        }
    })
<<<<<<< HEAD
=======
}
// 取消添加
function qxtj() {
    $('.gl').css('display', 'block')
    $('.tj').css('display', 'none')
    $('.p1 span').html("")
    $('.p1 span').html("/讲师列表")
    fetchData(1)
}
// 注销
function zx(id) {
    $.ajax({
        url: 'http://47.94.4.201/index.php/index/teacher/delteacher?id=' + id,
        type: 'get',
        dataType: 'json',
        success: (a) => {
            alert(a.msg)
            fetchData(1)
        },
        error: (e) => {
            console.log(e);
        }
    })
}
// 搜索
function ss() {
    var name = $('.ss').val()
    $.ajax({
        url: 'http://47.94.4.201/index.php/index/teacher/getsearch?name=' + name,
        type: 'get',
        dataType: 'json',
        success: (a) => {
            $('#data-list').html('')
            a.data.data.forEach(item => {
                $('#data-list').append(`<tr>
                            <td>${item.id}</td>
                            <td>${item.name}</td>
                            <td>${item.nick}</td>
                            <td>${item.birthdata}</td>
                            <td>${item.sex}</td>
                            <td>${item.teachertype}</td>
                            <td><button onclick="view(${item.id})">查看</button><button onclick="xg(${item.id})">编辑</button><button onclick="zx(${item.id})">注销</button></td>
                        </tr>`)
            })


        },
        error: (e) => {
            console.log(e);

        }
    })
}
// tab切换
var a = document.querySelectorAll('.a')
var b1 = document.querySelector('.b')
var b = document.querySelectorAll('.b')
var c = document.querySelectorAll('.c')
var gr = document.querySelector('.gr')
var grzx = document.querySelector('.grzx')
a.forEach((item, index) => {
    item.addEventListener('click', () => {
        b.forEach(item2 => {
            item2.classList.remove('show')
        })
        b[index].classList.add('show')
    })
})
c.forEach((item) => {
    item.addEventListener('click', () => {
        c.forEach((item2) => {
            if (item2 !== item) {
                item2.classList.remove('shom');
            }
        });
        item.classList.toggle('shom');
    });
});
gr.addEventListener('click', () => {
    a.forEach(item => {
        item.classList.remove('shom');
    });
})
function grfh() {
    grzx.classList.toggle('show')
    b1.classList.toggle('show')
    document.querySelector('.a1').classList.toggle('shom')
}
// 图表
// 基本雷达图
// 基于准备好的dom，初始化echarts实例
var myChart = echarts.init(document.getElementById('main'));

// 指定图表的配置项和数据
var option = {
    title: {
        text: '讲师图例数据'
    },
    tooltip: {},
    legend: {
        data: ['销量']
    },
    xAxis: {
        data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
    },
    yAxis: {},
    series: [
        {
            name: '销量',
            type: 'bar',
            data: [5, 20, 36, 10, 10, 20]
        }
    ]
};

// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);

// 退出
function tc() {
    location.assign('./登录.html')
<<<<<<< HEAD
}

=======
>>>>>>> ccd5b64437f1fc8839e14dad53dc55171b191804
}
>>>>>>> d7f987ffae4259d01a9a73690d4ed924d9055da2
